package problemSpace;

import java.util.ArrayList;
import java.util.Date;

import javax.xml.bind.annotation.XmlTransient;

@XmlTransient
public class timeInterval {
	private Date start;
	private Date end;
	public String orderCode;

	public timeInterval(Date start, Date end, String orderCode) {
		this.start = start;
		this.end = end;
		this.orderCode = orderCode;
	}

	public timeInterval(timeInterval ti) {
		this.start = ti.start;
		this.end = ti.end;
		this.orderCode = ti.orderCode;
	}

	/**
	 * Checks the timeInterval for overlap in an ArrayList of timeIntervals
	 * @param occupied List of time intervals
	 * @return true if the list contains an interval that overlaps the given one
	 */
	public boolean overlaps(ArrayList<timeInterval> occupied) {
		if (occupied.size() < 1)
			return false;
		for (timeInterval t : occupied) {
			if (t.end.getTime() > start.getTime()
					&& t.start.getTime() < end.getTime())
				return true;
		}
		return false;
	}

	public Date getStart() {
		return start;
	}

	public Date getEnd() {
		return end;
	}
	
	public String toString(){
		return "Order "+orderCode+" start "+start+" end "+end;
	}

}
